﻿CREATE PROCEDURE [dbo].[s_Tracker__Installed]
	@TrackerID varchar(8000) = NULL,
	@TrackerRequestID int = 0
AS

IF NOT(@TrackerID > '' OR @TrackerRequestID > 0) BEGIN
	ROLLBACK TRAN
	RAISERROR('TrackerID(s) or TrackerRequestID must be provided.',16,1)
	RETURN
END

IF @TrackerID > '' AND @TrackerRequestID > 0 BEGIN
	ROLLBACK TRAN
	RAISERROR('Either TrackerID(s) or TrackerRequestID can be provided.',16,1)
	RETURN
END

/**/DECLARE @CI int EXEC @CI = sp__Context_WorkFlow_System 1

IF @TrackerID > ''
	UPDATE t_Tracker SET StatusID = dbo.Tracker_Status__Installed()
	WHERE ID IN (SELECT Element FROM Split(@TrackerID,','))
IF @@ERROR <> 0 ROLLBACK TRAN


IF @TrackerRequestID > 0
	UPDATE t_Tracker SET StatusID = dbo.Tracker_Status__Installed()
	WHERE ID IN (SELECT TrackerID FROM t_Tracker_Car WHERE TrackerRequestID = @TrackerRequestID)
IF @@ERROR <> 0 ROLLBACK TRAN
/**/EXEC sp__Context @CI


